<link rel="stylesheet" href="css/index.css"/>
<script src="js/jquery-3.4.1.js"></script>
<script src="js/vue.js"></script>
<script src="js/axios.js"></script>
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="js/menu.js"></script>

<div id="app" style="height: 100%;">
    <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">位置</el-breadcrumb-item>
        <el-breadcrumb-item>月度报表</el-breadcrumb-item>
        <el-breadcrumb-item>月度收支报表</el-breadcrumb-item>
    </el-breadcrumb>
    <br/>
    <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-form-item label="日期:">
            <div class="block">
                <el-date-picker
                        v-model="form.date"
                        type="month"
                        placeholder="选择月"
                        value-format="yyyy-MM">
                </el-date-picker>
            </div>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" size="middle" @click="onsubmit">查询</el-button>
        </el-form-item>
    </el-form>
    <div>
        <el-table :data="tableDataCount" height="100px" border style="width: 100%">
            <el-table-column prop="inPrice" label="收款总金额" width="180"></el-table-column>
            <el-table-column prop="outPrice" label="付款总金额" width="180"></el-table-column>
            <el-table-column prop="inPriceCount" label="收款交易次数" width="180"></el-table-column>
            <el-table-column prop="outPriceCount" label="付款交易次数" width="180"></el-table-column>
        </el-table>
    </div>
    <el-menu
            :default-active="activeMenu"
            class="el-menu-demo"
            mode="horizontal"
            @select="handleSelect"
            active-text-color="#ffd04b">
        <el-menu-item index="1" value="1">月度付款记录</el-menu-item>
        <el-menu-item index="2" value="2">月度收款记录</el-menu-item>
    </el-menu>
    <div>
        <el-table :data="tableDataDetailsPayMoney" height="250px" border style="width: 100%" v-if="payMoney">
            <el-table-column prop="ordercode" label="采购单号" width="180"></el-table-column>
            <el-table-column prop="createTime" label="采购日期" width="180"></el-table-column>
            <el-table-column prop="payTime" label="付款日期" width="180"></el-table-column>
            <el-table-column prop="payPrice" label="付款金额" width="180"></el-table-column>
            <el-table-column prop="account" label="经手人" width="180"></el-table-column>
            <el-table-column prop="status" label="处理状态" width="180">
                <template slot-scope="scope">
                    <span v-if="scope.row.status==1">新建</span>
                    <span v-else-if="scope.row.status==2">收货</span>
                    <span v-else-if="scope.row.status==3">付款</span>
                    <span v-else-if="scope.row.status==4">了结</span>
                    <span v-else-if="scope.row.status==5">预付</span>
                </template>
            </el-table-column>
        </el-table>
    </div>
    <div>
        <el-table :data="tableDataDetailsInMoney" height="250px" border style="width: 100%" v-if="inMoney">
            <el-table-column prop="ordercode" label="销售单号" width="180"></el-table-column>
            <el-table-column prop="createTime" label="销售日期" width="180"></el-table-column>
            <el-table-column prop="payTime" label="收款日期" width="180"></el-table-column>
            <el-table-column prop="payPrice" label="收款金额" width="180"></el-table-column>
            <el-table-column prop="account" label="经手人" width="180"></el-table-column>
            <el-table-column prop="status" label="处理状态" width="180">
                <template slot-scope="scope">
                    <span v-if="scope.row.status==1">新建</span>
                    <span v-else-if="scope.row.status==2">收货</span>
                    <span v-else-if="scope.row.status==3">付款</span>
                    <span v-else-if="scope.row.status==4">了结</span>
                    <span v-else-if="scope.row.status==5">预付</span>
                </template>
            </el-table-column>
        </el-table>
    </div>

    <el-pagination
            background
            layout="sizes, prev, pager, next, jumper, ->, total, slot"
            :total="totalRecord"
            :current-page="currentPage"
            :page-size="pageSize"
            :page-sizes="[6,10,15,20]"
            @current-change="handleCurrentChange"
            @size-change="handleSize">
    </el-pagination>
    <!--    :visible.sync="inMoney"-->
    <!--供应商弹框-->
</div>

<script>
    window.onload = function () {

        let vm = new Vue({
            el: "#app",
            data: {
                labelPosition: "left",
                dialogFormVisible: false,
                tableDataCount: [],
                tableDataDetailsPayMoney: [],
                tableDataDetailsInMoney: [],
                options: [],
                totalRecord: 0,
                currentPage: 1,
                pageSize: 6,
                payMoney: true,
                inMoney: false,
                payType: 1,
                activeMenu: "",
                form: {
                    date: ""
                }
            },
            methods: {
                init: function () {
                    this.handleSelect(this.payType);
                },
                handleCurrentChange: function (val) {
                    this.currentPage = val;
                    this.handleSelect(this.payType);
                },
                handleSize: function (val) {
                    this.pageSize = val;
                    this.handleSelect(this.payType);
                },
                handleSelect: function (index) {
                    console.log(index)
                    this.activeMenu = index;
                    window.localStorage.setItem('activeMenu', this.activeMenu);
                    this.payType = index;
                    let that = this;
                    if (index == 1) {
                        this.payMoney = true;
                        this.inMoney = false;
                        axios.get("getPayRecord1?currentPage=" + this.currentPage + "&pageSize=" + this.pageSize + "&date=" + this.form.date).then(function (resp) {
                            that.tableDataDetailsPayMoney = resp.data.data.lists;
                            that.totalRecord = resp.data.data.totalRecord;
                        });
                    }
                    if (index == 2) {
                        this.inMoney = true;
                        this.payMoney = false;
                        axios.get("getPayRecord?currentPage=" + this.currentPage + "&pageSize=" + this.pageSize + "&date=" + this.form.date).then(function (resp) {
                            console.log(resp.data.data.lists)
                            that.tableDataDetailsInMoney = resp.data.data.lists;
                            that.totalRecord = resp.data.data.totalRecord;
                        });
                    }

                    //查询采购单各种总数
                    axios.get("getPrice?date"+this.form.date).then(function (resp){
                        console.log(resp.data);
                        that.tableDataCount = resp.data;
                    });
                    this.currentPage = 1;
                },
                onsubmit:function () {
                    if(this.form.date == null){
                        this.form.date = "";
                    }
                    /*模糊查询*/
                    this.currentPage = 1;
                    this.init();
                },
            }
        });
        vm.init();
    }
</script>